define(function (require, exports, module) {
    require("apps/easyui");

    $.widget("custom.gridSelect", {
            options: {
                dataOptions:"",
                textbox: $.noop,
                method:"",
                href:"",
                title:"选择",
                setValue: $.noop
            },
            _create: function () {
                var $this = this;
                this.element.linkbutton({
                        onClick:function(){
                            $this._openDialog();
                        }
                    });
                this.pageWindow = new $.PageWindow();
            },
            addValues:function(values){
                if(values.length){
                    this.options.setValue.call(this, values);
                }
            },
            _render:function(selected){
                if(selected.length){
                    this.options.setValue.call(this, selected);
                }
            },
            _openDialog: function(){
                var $this = this;
                this.pageWindow.create({
                    href: this.options.href,
                    method: this.options.method,
                    title: this.options.title,
                    width: 800,
                    callback: function (status, json) {
                        if (status) {
                            var postData = json.postData;
                            $this._render(postData);
                        }
                    }
                });
                this.pageWindow.open();
            }
        }
    )
});